<template xmlns:text-align="http://www.w3.org/1999/xhtml">
<div>
  <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
    <el-breadcrumb-item :to="{ path: '/' }">
      <i class="el-icon-s-promotion"></i> 后台首页
    </el-breadcrumb-item>
    <el-breadcrumb-item>商品报销清单</el-breadcrumb-item>
  </el-breadcrumb>
  <el-divider></el-divider>
    <!--点击搜索按钮的模糊查询-->
  <div style="margin: 15px 0;" class="fuzzy-query">
    <el-input placeholder="输入关键字" v-model="input" class="input-with-select">
      <el-select v-model="select" slot="prepend" placeholder="请选择" class="el-input-group__prepend">
        <el-option label="商品名" value="1"></el-option>
        <el-option label="供应商" value="2"></el-option>
        <el-option label="提交人姓名" value="3"></el-option>
      </el-select>
      <el-button slot="append" icon="el-icon-search" @click="fuzzyQuery"></el-button>
    </el-input>
  </div>
    <!--报销清单数据表格-->
  <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="100" align="center"></el-table-column>
      <el-table-column prop="goodsName" label="商品名称" header-align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="breakageNum" label="报销数量" width="80" align="center"></el-table-column>
      <el-table-column prop="providerName" label="供应商" header-align="center"   show-overflow-tooltip></el-table-column>
      <el-table-column prop="producePlace" label="生产产地" header-align="center"   show-overflow-tooltip></el-table-column>
      <el-table-column prop="description" label="报销原因" width="180" align="center"></el-table-column>
      <el-table-column prop="submitName" label="提交人" width="180" align="center"></el-table-column>
      <el-table-column prop="gmtCreate" label="提交时间" width="180" align="center"></el-table-column>
      <el-table-column prop="operation" label="操作" width="180" header-align="center">

      </el-table-column>
    </el-table>
  <!--分页控件-->
  <span class="demonstration"></span>
  <div style="margin:20px 0; text-align: right;">
    <el-pagination
        layout="total,prev, pager, next"
        @current-change="changePage"
        :page-size="pageSize"
        :current-page="currentPage"
        :total="total">
    </el-pagination>
  </div>
   <div style="margin:20px 0; text-align: center;" >
     <el-button type="primary"  @click="dialogFormVisible = true"  plain>报损</el-button>
     <el-dialog title="新增报损" :visible.sync="dialogFormVisible">
       <el-form :model="editForm" :rules="rules" ref="ruleForm" label-width="100px">
         <el-form-item label="商品名">
           <el-input v-model="editForm.goodsName" autocomplete="off"></el-input>
         </el-form-item>
         <el-form-item label="报损数量" >
           <el-input v-model="editForm.breakageNum" autocomplete="off"></el-input>
         </el-form-item>
         <el-form-item label="报损原因">
           <el-input v-model="editForm.description" autocomplete="off"></el-input>
         </el-form-item>
         <el-form-item label="提交人">
           <el-input v-model="editForm.submitName" autocomplete="off"></el-input>
         </el-form-item>
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button @click="dialogFormVisible = false">取 消</el-button>
         <el-button type="primary" @click="submitEditForm">确 定</el-button>
       </div>
     </el-dialog>
   </div>
</div>
</template>
<style>
  .fuzzy-query{
    float: left;
    margin-top: 12px;
    display: flex;
  }

  .fuzzy-query .input-with-select  {
    width:500px;
    background-color: #fff;
  }
  .fuzzy-query .input-with-select .el-input-group__prepend{
    width: 100px;
  }
</style>
<script>
export default {
  data() {
    return {
      tableData: [
      ],
      total: 0,
      pageSize: 0,
      currentPage: 0,
      input:'',
      select: '1',
      editForm:{
        goodsName:'',
        breakageNum:'',
        description:'',
        submitName:'',
      },
      dialogFormVisible: false,
      rules: {
        goodsName: [
          {required: true, message: '商品名', trigger: 'blur'},

        ],
        breakageNum: [
          {required: true, message: '报损数量', trigger: 'blur'}
        ],
        description: [
          {required: true, message: '报损原因', trigger: 'blur'},
        ],
        submitName: [
          {required: true, message: '提交人', trigger: 'blur'},
        ]
      }
    }
  },
  methods:{
    submitEditForm(){
      let url = 'http://localhost:9090/breakage/affirm';
      let formData = this.qs.stringify(this.editForm);
      this.axios.post(url, formData).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.$message({
            message: '新增报销成功！',
            type: 'success'
          });
          this.dialogFormVisible = false;
          this.loadBreakageList();
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
              this.dialogFormVisible = false;
              this.loadBreakageList();
            }
          });
        }
      });
    },
    fuzzyQuery()
    {
      //取网址上的值
      let pageNum=this.$router.currentRoute.query.pageNum;
      if(!pageNum){pageNum=1;}
      let url='http://localhost:9090/breakage/query-type?select='+this.select+'&input='+this.input+'&pageNUm='+pageNum;
      this.axios.get(url).then((response)=>{
        let jsonResult=response.data;
        if(jsonResult.state==20000)
        {
          this.tableData=jsonResult.data.list;
          this.total= jsonResult.data.total;
          this.pageSize=jsonResult.data.pageSize;
          this.currentPage=jsonResult.data.currentPage;
        }else{
          let title='操作失败';
          this.$alert(jsonResult.message,title,{
            confirmButtonText:'确定',
            callback:action => {

            }
          });
        }
      });
    },
    changePage(pageNum)
    {
      this.$router.replace('?pageNum='+pageNum)
      this.loadBreakageList();
    },
    loadBreakageList()
    {
      //取网址上的值
      let pageNum=this.$router.currentRoute.query.pageNum;
      if(!pageNum){pageNum=1;}
      let url='http://localhost:9090/breakage/show?pageNum='+pageNum;
      this.axios.get(url).then((response)=>{
        let jsonResult=response.data;
        if(jsonResult.state==20000)
        {
          this.tableData=jsonResult.data.list;
          this.total= jsonResult.data.total;
          this.pageSize=jsonResult.data.pageSize;
          this.currentPage=jsonResult.data.currentPage;
        }else{
          let title='操作失败';
          this.$alert(jsonResult.message,title,{
            confirmButtonText:'确定',
            callback:action => {

            }
          });
        }
      });
    }
  },
  mounted(){
    this.loadBreakageList();
  }
}
</script>
